/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"28CCF603-BF02-4D30-AACA-89363E524DCD"}
 */
var fFrom = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"A23ECB9F-0A15-4A9E-84D0-7193334475F4"}
 */
var fAdjuntos = '';

/**
 * @type {Array<plugins.mail.Attachment>}
 *
 * @properties={typeid:35,uuid:"A3351B8C-004D-4C27-8CBE-54CCA5EC41F3",variableType:-4}
 */
var fAdjuntos2 = new Array();

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"3B03B832-5C7A-4CE4-A9C6-2FC0F74B134D"}
 */
var fMensaje = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"7CD86C48-D90E-40BB-B4FE-C026E66D53D2"}
 */
var fAsunto = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"7A888D7B-A9C8-4522-8EBC-104112A7D175"}
 */
var fDestino = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"7557863F-E8D2-4ACA-AF45-4F12C819762F",variableType:4}
 */
var fHash = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"6B8E8B34-2591-42D6-A3EA-3625617B4218"}
 */
var fPass = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"B3EB380B-D8B5-4DE2-AC77-B2D8DB84F0AF"}
 */
var fRemitente = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"EEFBA7A5-7573-420A-B95B-ABEE1315F78E",variableType:4}
 */
var fPuerto = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"1E3220E3-FE9B-490D-82EC-EA7D71961173"}
 */
var fHost = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"2EA7FEE3-BC37-4064-9E8F-9935CE349560"}
 */
function enviar(event) {
	
	var params = {
		processFunction: enviar2,
		message: 'Mandando mail...',
		opacity: 0.5,
		paneColor: '#c0c0c0'
	};
	plugins.busy.block( params);
}

/**
 * @properties={typeid:24,uuid:"D1EFFC59-7F74-47B6-9CC3-D9EED70B8C6C"}
 */
function enviar2 ()
{
	try{
		var $mando = globals.mandarMail(fHost,fPuerto,fRemitente,fFrom,fPass,fHash,fDestino,fAsunto,fMensaje,fAdjuntos2)
		if (!$mando)
		{
			var error = plugins.mail.getLastSendMailExceptionMsg()
			application.output(error)
		}
		else
		{
			application.output('Mensaje Enviado')
		}
	}
	catch (e){
		globals.DIALOGS.showWarningDialog('Aviso','Ocurrio un error al mandar el mail','OK')
		application.output(e)
	}
	finally{
		plugins.busy.unblock()
	
	}
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"F8FA2382-B832-467E-A9AD-FC1DC89770EA"}
 */
function buscarArchivo(event) {
	/** @type {plugins.file.JSFile} */
	var f = plugins.file.showFileOpenDialog(1,null,false,null,null,'Elija un archivo')
	
	if (fAdjuntos2 == null)
	{
		fAdjuntos = ''
		fAdjuntos2 = new Array()
	}
	fAdjuntos += f.getPath()+';'
	fAdjuntos2.push(plugins.mail.createBinaryAttachment( f.getName(), plugins.file.readFile(f.getPath())))
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"A7175D77-D738-4696-94CD-FC3C45204C33"}
 */
function cargarDefaults(event) {
	fHost 		= 'smtp.gmail.com';
	fPuerto 	= 587;
	fHash 		= 0;
	fPass 		= 'servoy2009';
	fRemitente 	= 'demoservoy@gmail.com';
	fFrom		= 'DEMO'
	fDestino 	= 'andres.achiary@gmail.com,andres_achiary@infocomsa.com.ar';
	fAsunto 	= 'Prueba';
	fMensaje 	= 'Este es un mensaje de prueba';
	fAdjuntos 	= ''
	fAdjuntos2 	= null//new Array()
}
